package com.tingyuge.base.thread.concurrent2;

/**
 * 死锁
 */
public class MyTest6 {

    private Object lock1 = new Object();
    private Object lock2 = new Object();

    public void method1(){
        synchronized (lock1){
            System.out.println("method1");
            try {
                Thread.sleep(1001);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            method2();
        }
    }

    public void method2(){
        synchronized (lock2){
            System.out.println("method1");
            method1();
        }
    }

    public static void main(String[] args) {
        MyTest6 myTest6 =  new MyTest6();
        new Thread(()->myTest6.method1()).start();
        new Thread(()->myTest6.method2()).start();
    }
}
